<template>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="gotoWaiting()">
        <div class="card-panel-icon-wrapper icon-bell">
          <svg-icon icon-class="bell" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            待办任务
          </div>
          <count-to :start-val="0" :end-val="waitingCount" :duration="3600" class="card-panel-num" />
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="gotoFinish()">
        <div class="card-panel-icon-wrapper icon-skill">
          <svg-icon icon-class="skill" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            已办任务
          </div>
          <count-to :start-val="0" :end-val="finishCount" :duration="1000" class="card-panel-num" />
        </div>
      </div>
    </el-col>

    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="gotoRunning()">
        <div class="card-panel-icon-wrapper icon-setting">
          <svg-icon icon-class="setting" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            正进行的申请
          </div>
          <count-to :start-val="0" :end-val="runningCount" :duration="3000" class="card-panel-num" />
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="gotoCompleted()">
        <div class="card-panel-icon-wrapper icon-example">
          <svg-icon icon-class="example" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            已结束的申请
          </div>
          <count-to :start-val="0" :end-val="completedCount" :duration="3200" class="card-panel-num" />
        </div>
      </div>
    </el-col>

  </el-row>
</template>

<script>
import CountTo from 'vue-count-to'
import request from '@/utils/request'
export default {
  components: {
    CountTo
  },
  data() {
    return {
      waitingCount: 0,
      finishCount: 0,
      runningCount: 0,
      completedCount: 0
    }
  },
  created() {
    this.getRuntimeTaskCount()
    this.getHistoryTaskCount()
    this.getHistoryProcessCount()
    this.getProcessInRunningCount()
  },
  methods: {
    getRuntimeTaskCount() {
      request({ url: '/task/getRuntimeTaskCount', method: 'get' })
        .then(res => {
          this.waitingCount = res
        })
        .catch(e => {
          this.waitingCount = 0
          // this.$message.error('查询出错')
        })
    },
    getHistoryTaskCount() {
      request({ url: '/task/getHistoryTaskCount', method: 'get' })
        .then(res => {
          this.finishCount = res
        })
        .catch(e => {
          this.finishCount = 0
          // this.$message.error('查询出错')
        })
    },
    getHistoryProcessCount() {
      request({ url: '/processInst/getHistoryProcessCount', method: 'get' })
        .then(res => {
          this.completedCount = res
        })
        .catch(e => {
          this.repairCount = 0
          // this.$message.error('查询出错')
        })
    },
    getProcessInRunningCount() {
      request({ url: '/processInst/getProcessInRunningCount', method: 'get' })
        .then(res => {
          this.runningCount = res
        })
        .catch(e => {
          this.runningCount = 0
          // this.$message.error('查询出错')
        })
    },
    gotoRunning() {
      return this.$router.push({ path: '/edu/processinst' })
    },
    gotoCompleted() {
      return this.$router.push({ path: '/edu/processinst?tabinx=2' })
    },

    gotoWaiting() {
      return this.$router.push({ path: '/edu/task' })
    },

    gotoFinish() {
      return this.$router.push({ path: '/edu/task?tabinx=2' })
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    display: flex;
    justify-content: center;

    .icon-skill {
      color: #40c9c6;
    }

    .icon-setting {
      color: #36a3f7;
    }

    .icon-example {
      color: #888888;
    }

    .icon-bell {
      color: #ff6600
    }

    .card-panel-icon-wrapper {
      margin: 14px 0 0 14px;
      padding: 16px 10px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      flex:1;
      font-weight: bold;
      margin: 26px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
